﻿using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace IM.Easy.Entity.Log
{
    /// <summary>
    /// 登录，注销操作
    /// </summary>
    [SugarTable]
    public class SessionLog
    {
        /// <summary>
        /// 日志唯一ID
        /// </summary>
        [SugarColumn(IsPrimaryKey = true)]
        public Guid Id { get; set; }

        /// <summary>
        /// 用户ID
        /// </summary>
        public long UserId { get; set; }

        /// <summary>
        /// 用户名
        /// </summary>
        public string UserName { get; set; }

        /// <summary>
        /// 操作类型：登录或注销
        /// </summary>
        public SessionType ActionType { get; set; }

        /// <summary>
        /// 操作时间
        /// </summary>
        public DateTime ActionTime { get; set; }

        /// <summary>
        /// 请求的唯一追踪ID，用于标识整个请求链路
        /// </summary>
        [SugarColumn(Length = 50)]
        public string? TraceIdentifier { get; set; }

        /// <summary>
        /// 操作描述或备注
        /// </summary>
        [SugarColumn(ColumnDataType = StaticConfig.CodeFirst_BigString)]
        public string? Description { get; set; }

        /// <summary>
        /// 终端信息（PC、Mobile、Tablet等）
        /// </summary>
        public TerminalType Terminal { get; set; }

        /// <summary>
        /// 追踪信息
        /// </summary>
        [Navigate(NavigateType.OneToOne, nameof(TraceIdentifier), nameof(RequestTrackingLog.TraceIdentifier))]
        public RequestTrackingLog TraceInfo { get; set; }
    }

    public enum SessionType
    {
        /// <summary>
        /// 登录
        /// </summary>
        Login = 0,

        /// <summary>
        /// 注销
        /// </summary>
        Logout = 1,
    }

    public enum TerminalType
    {
        /// <summary>
        /// 电脑
        /// </summary>
        PC = 0,
        /// <summary>
        /// 手机
        /// </summary>
        Mobile = 1
    }
}
